/**
 * Created by m on 2019/1/10.
 */
$(function () {
    $("#toCc").click(function () {
        window.location.href="PositionTrackingList.html?loginName=" + _loginName + "&token=" + _token
    });

    function getTable(strategyId,sortType,page) {
        var _timestamp = new Date().getTime();
        var _secret = hex_md5(ip + '/Back/Strategy/AllTrade1111?timestamp='+ _timestamp +salt);
        $.ajax({
            type:"POST",
            url:ip + '/Back/Strategy/AllTrade1111?timestamp=' + _timestamp + '&secret=' + _secret + '&token=' + _token,
            dataType:'json',
            headers:{
                "Content-Type": "application/json",
                "Accept": "application/json;charset=utf-8",
            },
            data:JSON.stringify({
                "strategyId" : strategyId,
                "sortType" : sortType,
                "page" : page
            }),
            success:function (data) {
                console.log(data);
                if (data.code == 1){
                    $("#warehouse_trackTable tbody tr").remove();
                    var count = data.data.length;
                    var number1 = 0;
                    var number2 = 0;

                    for(let i = 0; i < count; i++){
                        var _count = i + 1;
                        var gmtCreate = data.data[i].gmtCreate;//(string, optional): 操作时间 ,
                        var profitRate = data.data[i].profitRate ||''; //(number, optional): 盈亏幅度 ,
                        var profitValue = data.data[i].profitValue ||'';//(number, optional): 盈亏金额 ,
                        var stockId = data.data[i].stockId;//(string, optional): 股票代码 ,
                        var stockTypeStr = data.data[i].stockTypeStr;//(string, optional): 期权，个股 ,
                        var tradeDirectionName = data.data[i].tradeDirectionName;//(string, optional): 交易方向多空 ,
                        var tradePrice = data.data[i].tradePrice;//(number, optional): 成本价 ,
                        var tradeValue = data.data[i].tradeValue;//(number, optional): 初始金额 ,
                        var tradeVolume = data.data[i].tradeVolume;//(integer, optional): 持仓股数
                        if(stockTypeStr =="个股"){
                            number1 =number1 + 1;
                            console.log(number1);
                            var tr1 ="<tr class='tr1' number="+number1+"stockTypeStr="+stockTypeStr+"stockId="+stockId+"tradeDirectionName="+tradeDirectionName+"tradePrice="+tradePrice+"profitRate="+profitRate+"profitValue="+profitValue+"tradeValue="+tradeValue+"tradeVolume="+tradeVolume+"gmtCreate="+gmtCreate+">" +
                                "<td>"+number1+"</td><td>"+stockTypeStr+"</td><td>"+stockId+"</td><td>"+tradeDirectionName+"</td><td>"+tradePrice+"</td><td>"+profitRate+"</td><td>"+profitValue+"</td><td>"+tradeValue+"</td><td>"+tradeVolume+"</td><td>"+getMyDate(gmtCreate)+"</td></tr>";
                            $("#warehouse_trackTable tbody").append(tr1);
                        }
                    }
                    var tr2 ="<tr><td colspan='10'></td></tr>"
                    $("#warehouse_trackTable tbody").append(tr2);
                    for(let i = 0; i < count; i++){
                        var _count = i + 1;
                        var gmtCreate = data.data[i].gmtCreate;//(string, optional): 操作时间 ,
                        var profitRate = data.data[i].profitRate || ''; //(number, optional): 盈亏幅度 ,
                        var profitValue = data.data[i].profitValue ||'';//(number, optional): 盈亏金额 ,
                        var stockId = data.data[i].stockId;//(string, optional): 股票代码 ,
                        var stockTypeStr = data.data[i].stockTypeStr;//(string, optional): 期权，个股 ,
                        var tradeDirectionName = data.data[i].tradeDirectionName;//(string, optional): 交易方向多空 ,
                        var tradePrice = data.data[i].tradePrice;//(number, optional): 成本价 ,
                        var tradeValue = data.data[i].tradeValue;//(number, optional): 初始金额 ,
                        var tradeVolume = data.data[i].tradeVolume;//(integer, optional): 持仓股数
                        if(stockTypeStr =="期权"){
                            number2 =number2 + 1;
                            console.log(number2);
                            var tr3 ="<tr class='tr3' number2="+number2+"stockTypeStr="+stockTypeStr+"stockId="+stockId+"tradeDirectionName="+tradeDirectionName+"tradePrice="+tradePrice+"profitRate="+profitRate+"profitValue="+profitValue+"tradeValue="+tradeValue+"tradeVolume="+tradeVolume+"gmtCreate="+gmtCreate+">" +
                                "<td>"+number2+"</td><td>"+stockTypeStr+"</td><td>"+stockId+"</td><td>"+tradeDirectionName+"</td><td>"+tradePrice+"</td><td>"+profitRate+"</td><td>"+profitValue+"</td><td>"+tradeValue+"</td><td>"+tradeVolume+"</td><td>"+getMyDate(gmtCreate)+"</td></tr>";
                            $("#warehouse_trackTable tbody").append(tr3);
                        }
                    }


                }
            },
            error: function () {
                alert('请求持仓跟踪列表失败');
            }
        })
    }
    getTable(1111,1,1);
})